package com.gxa.uhome.service.impl;

import com.gxa.uhome.exception.BusinessException;
import com.gxa.uhome.mapper.OrderMapper;
import com.gxa.uhome.pojo.Order;
import com.gxa.uhome.pojo.UserOrder;
import com.gxa.uhome.service.OrderService;
import com.gxa.uhome.util.ExportUtil;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: Laiguowei
 * @date: 9:46 2021/6/10
 **/
@Service
public class OrderServiceImpl implements OrderService {

    @Resource
    OrderMapper orderMapper = null;

    @Override
    public Integer createOrder(Order order) {
        Integer order1 = orderMapper.createOrder(order);
        return order1;
    }

    @Override
    public Integer updateOrder(Order order) {
        Integer integer = orderMapper.updateOrder(order);
        return integer;
    }

    @Override
    public Integer shipOrder(Integer shipperId, Integer orderId) {
        Integer integer = orderMapper.shipOrder(shipperId, orderId);
        return integer;
    }

    @Override
    public List<Map<String, Object>> selectByPage(Map<String, Object> map) {
        List<Map<String, Object>> list = orderMapper.selectByPage(map);
        return  list;
    }

    @Override
    public UserOrder getDetailByOrderId(Integer id) {
        UserOrder detailByOrder = orderMapper.getDetailByOrderId(id);
        System.out.println(detailByOrder);
        return  detailByOrder;
    }

    @Override
    public HSSFWorkbook export( HttpServletResponse response ) throws Exception {
        Map<String,Object> map=new HashMap<>();
        List<Map<String, Object>> list = orderMapper.selectByPage(map);
        String[] headers = {"订单编号","货物类别","商品数量","箱数","商品金额","重量","订单状态","收件人","联系方式","配送人","配送时间","" +
                "失效产品","所属站点"};
        String[] a={"orderNo", "goodsTypeName", "goodsCount", "boxCount", "price", "weight",
                "status", "name", "phone", "shipperName", "time", "expireProduct", "stationName"};
        HSSFWorkbook export = ExportUtil.export(list, headers,a,"订单表",response);
        return export;
    }
}
